package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.*;
import com.doyens.gmall.product.service.MangeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Classname:BaseManageController
 * PackageName:com.doyens.gmall.product.controller
 *
 * @Author:uyijk
 * @Create:2023/7/25 11:25
 * @Version: 1.0
 */
@Api(tags = "商品基础属性接口")
@Controller
@RequestMapping("admin/product")
public class BaseManageController {
    @Autowired
    private MangeService mangeService;
    @GetMapping("getCategory1")
    @ResponseBody
    public Result<List<BaseCategory1>> getCategory1(){
        List<BaseCategory1> category1List = mangeService.getCategory1();
        return Result.ok(category1List);
    }

    @GetMapping("getCategory2/{category1Id}")
    @ResponseBody
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id){
        List<BaseCategory2> category2List = mangeService.getCategory2(category1Id);
        return Result.ok(category2List);
    }

    @GetMapping("getCategory3/{category2Id}")
    @ResponseBody
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> category3List = mangeService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    @ResponseBody
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id")Long category1Id,
                                                   @PathVariable("category2Id")Long category2Id,
                                                   @PathVariable("category3Id")Long category3Id){
        List<BaseAttrInfo> baseAttrInfoList = mangeService.getAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }

    @PostMapping("saveAttrInfo")
    @ResponseBody
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        mangeService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("getAttrValueList/{attrId}")
    @ResponseBody
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> baseAttrValueList = mangeService.getAttrValueList(attrId);
        return Result.ok(baseAttrValueList);
    }
}
